/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.messages.web;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.messages.entity.EleEquipmentMessages;
import com.thinkgem.jeesite.modules.messages.service.EleEquipmentMessagesService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.support.RequestContextUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * 报文查询Controller
 * @author 报文查询
 * @version 2017-06-13
 */
@Controller
@RequestMapping(value = "${adminPath}/messages/eleEquipmentMessages")
public class EleEquipmentMessagesController extends BaseController {

	@Autowired
	private EleEquipmentMessagesService eleEquipmentMessagesService;
	
	@ModelAttribute
	public EleEquipmentMessages get(@RequestParam(required=false) String id) {
		EleEquipmentMessages entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = eleEquipmentMessagesService.get(id);
		}
		if (entity == null){
			entity = new EleEquipmentMessages();
		}
		return entity;
	}
	
	@RequiresPermissions("messages:eleEquipmentMessages:view")
	@RequestMapping(value = {"list", ""})
	public String list(EleEquipmentMessages eleEquipmentMessages, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<EleEquipmentMessages> page = eleEquipmentMessagesService.findPage(new Page<EleEquipmentMessages>(request, response), eleEquipmentMessages); 
		model.addAttribute("page", page);
		Locale locale = RequestContextUtils.getLocaleResolver(request).resolveLocale(request);
		if(locale.getLanguage().equals("zh")) {
			model.addAttribute("language", locale.getLanguage()+"-cn");
		}else {
			model.addAttribute("language", locale.getLanguage());
		}
		return "modules/messages/eleEquipmentMessagesList";
	}

	@RequiresPermissions("messages:eleEquipmentMessages:view")
	@RequestMapping(value = "form")
	public String form(EleEquipmentMessages eleEquipmentMessages, Model model) {
		model.addAttribute("eleEquipmentMessages", eleEquipmentMessages);
		return "modules/messages/eleEquipmentMessagesForm";
	}
}